/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "sector")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Sector.findAll", query = "SELECT s FROM Sector s ORDER BY s.description"),
    @NamedQuery(name = "Sector.findByIdSector", query = "SELECT s FROM Sector s WHERE s.idSector = :idSector"),
    @NamedQuery(name = "Sector.findByDescription", query = "SELECT s FROM Sector s WHERE s.description = :description")})
public class Sector implements Serializable, Comparable<Sector>, InternationalizableEntity {
    @OneToMany(mappedBy = "sector", fetch = FetchType.LAZY)
    private List<SearchInterestAreaRequerimentOrOperator> searchInterestAreaRequerimentOrOperatorList;
    @OneToMany(mappedBy = "sector", fetch = FetchType.LAZY)
    private List<SearchProfessionalInfoRequerimentOrOperator> searchProfessionalInfoRequerimentOrOperatorList;
    @OneToMany(mappedBy = "sector", fetch = FetchType.LAZY)
    private List<SearchInterestAreaRequerimentAndOperator> searchInterestAreaRequerimentAndOperatorList;
    @OneToMany(mappedBy = "sector", fetch = FetchType.LAZY)
    private List<SearchProfessionalInfoRequerimentAndOperator> searchProfessionalInfoRequerimentAndOperatorList;
    @OneToMany(mappedBy = "sector", fetch = FetchType.LAZY)
    private List<SearchEducationalInfoRequerimentAndOperator> searchEducationalInfoRequerimentAndOperatorList;
    @OneToMany(mappedBy = "sector", fetch = FetchType.LAZY)
    private List<SearchEducationalInfoRequerimentOrOperator> searchEducationalInfoRequerimentOrOperatorList;
    @OneToMany(mappedBy = "professionalInfoSector", fetch = FetchType.LAZY)
    private List<Search> searchList;
    @OneToMany(mappedBy = "educationalInfoSector", fetch = FetchType.LAZY)
    private List<Search> searchList1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idSector", fetch = FetchType.LAZY)
    private List<CompanySector> companySectorList;
    @OneToMany(mappedBy = "sector", fetch = FetchType.LAZY)
    private List<CandidateInterestArea> candidateInterestAreaList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sector", fetch = FetchType.LAZY)
    private List<CandidateProfessionalInfo> candidateProfessionalInfoList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_SECTOR")
    private Integer idSector;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "DESCRIPTION")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sector", fetch = FetchType.LAZY)
    private List<CandidateEducationalInfo> candidateEducationalInfoList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sector", fetch = FetchType.LAZY)
    private List<SectorDescription> sectorDescriptionList;

    public Sector() {
    }

    public Sector(Integer idSector) {
        this.idSector = idSector;
    }

    public Sector(Integer idSector, String description) {
        this.idSector = idSector;
        this.description = description;
    }

    public Integer getIdSector() {
        return idSector;
    }

    public void setIdSector(Integer idSector) {
        this.idSector = idSector;
    }

    @Override
    public String getDescription() {
        /*String resDescription=description;
        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
        if(!getSectorDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
            String localeCode=currentLocale.getLanguage();
            for(SectorDescription cd:getSectorDescriptionList()){
                if(cd.getLanguage().getCode().equals(localeCode)){
                    resDescription=cd.getDescription();
                }
            }
        }
        return resDescription;*/
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public List<CandidateEducationalInfo> getCandidateEducationalInfoList() {
        return candidateEducationalInfoList;
    }

    public void setCandidateEducationalInfoList(List<CandidateEducationalInfo> candidateEducationalInfoList) {
        this.candidateEducationalInfoList = candidateEducationalInfoList;
    }

    @XmlTransient
    public List<SectorDescription> getSectorDescriptionList() {
        return sectorDescriptionList;
    }

    public void setSectorDescriptionList(List<SectorDescription> sectorDescriptionList) {
        this.sectorDescriptionList = sectorDescriptionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idSector != null ? idSector.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Sector)) {
            return false;
        }
        Sector other = (Sector) object;
        if ((this.idSector == null && other.idSector != null) || (this.idSector != null && !this.idSector.equals(other.idSector))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Sector[ idSector=" + idSector + " ]";
    }

    @XmlTransient
    public List<CandidateProfessionalInfo> getCandidateProfessionalInfoList() {
        return candidateProfessionalInfoList;
    }

    public void setCandidateProfessionalInfoList(List<CandidateProfessionalInfo> candidateProfessionalInfoList) {
        this.candidateProfessionalInfoList = candidateProfessionalInfoList;
    }

    @XmlTransient
    public List<CandidateInterestArea> getCandidateInterestAreaList() {
        return candidateInterestAreaList;
    }

    public void setCandidateInterestAreaList(List<CandidateInterestArea> candidateInterestAreaList) {
        this.candidateInterestAreaList = candidateInterestAreaList;
    }

    @XmlTransient
    public List<CompanySector> getCompanySectorList() {
        return companySectorList;
    }

    public void setCompanySectorList(List<CompanySector> companySectorList) {
        this.companySectorList = companySectorList;
    }

    @XmlTransient
    public List<Search> getSearchList() {
        return searchList;
    }

    public void setSearchList(List<Search> searchList) {
        this.searchList = searchList;
    }

    @XmlTransient
    public List<Search> getSearchList1() {
        return searchList1;
    }

    public void setSearchList1(List<Search> searchList1) {
        this.searchList1 = searchList1;
    }

    @XmlTransient
    public List<SearchInterestAreaRequerimentOrOperator> getSearchInterestAreaRequerimentOrOperatorList() {
        return searchInterestAreaRequerimentOrOperatorList;
    }

    public void setSearchInterestAreaRequerimentOrOperatorList(List<SearchInterestAreaRequerimentOrOperator> searchInterestAreaRequerimentOrOperatorList) {
        this.searchInterestAreaRequerimentOrOperatorList = searchInterestAreaRequerimentOrOperatorList;
    }

    @XmlTransient
    public List<SearchProfessionalInfoRequerimentOrOperator> getSearchProfessionalInfoRequerimentOrOperatorList() {
        return searchProfessionalInfoRequerimentOrOperatorList;
    }

    public void setSearchProfessionalInfoRequerimentOrOperatorList(List<SearchProfessionalInfoRequerimentOrOperator> searchProfessionalInfoRequerimentOrOperatorList) {
        this.searchProfessionalInfoRequerimentOrOperatorList = searchProfessionalInfoRequerimentOrOperatorList;
    }

    @XmlTransient
    public List<SearchInterestAreaRequerimentAndOperator> getSearchInterestAreaRequerimentAndOperatorList() {
        return searchInterestAreaRequerimentAndOperatorList;
    }

    public void setSearchInterestAreaRequerimentAndOperatorList(List<SearchInterestAreaRequerimentAndOperator> searchInterestAreaRequerimentAndOperatorList) {
        this.searchInterestAreaRequerimentAndOperatorList = searchInterestAreaRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchProfessionalInfoRequerimentAndOperator> getSearchProfessionalInfoRequerimentAndOperatorList() {
        return searchProfessionalInfoRequerimentAndOperatorList;
    }

    public void setSearchProfessionalInfoRequerimentAndOperatorList(List<SearchProfessionalInfoRequerimentAndOperator> searchProfessionalInfoRequerimentAndOperatorList) {
        this.searchProfessionalInfoRequerimentAndOperatorList = searchProfessionalInfoRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchEducationalInfoRequerimentAndOperator> getSearchEducationalInfoRequerimentAndOperatorList() {
        return searchEducationalInfoRequerimentAndOperatorList;
    }

    public void setSearchEducationalInfoRequerimentAndOperatorList(List<SearchEducationalInfoRequerimentAndOperator> searchEducationalInfoRequerimentAndOperatorList) {
        this.searchEducationalInfoRequerimentAndOperatorList = searchEducationalInfoRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchEducationalInfoRequerimentOrOperator> getSearchEducationalInfoRequerimentOrOperatorList() {
        return searchEducationalInfoRequerimentOrOperatorList;
    }

    public void setSearchEducationalInfoRequerimentOrOperatorList(List<SearchEducationalInfoRequerimentOrOperator> searchEducationalInfoRequerimentOrOperatorList) {
        this.searchEducationalInfoRequerimentOrOperatorList = searchEducationalInfoRequerimentOrOperatorList;
    }

    @Override
    public int compareTo(Sector t) {
        return getDescription().compareToIgnoreCase(t.getDescription());
    }

    @Override
    public Integer getId() {
        return getIdSector();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getSectorDescriptionList();
    }
    
}
